<template>
  <div class="app-container">
    <el-card header="基础信息" style="width: 100%">
      <div slot="header" class="clearfix">
        <span>基础信息</span>
        <el-button
          type="success"
          @click="handleSave(2)"
          size="mini"
          style="float: right; margin: 0px 10px"
          v-hasPermi="[modulePermi + ':submit']"
        >
          模具验收完成
        </el-button>
        <el-button
          type="primary"
          @click="handleSave(1)"
          size="mini"
          style="float: right; margin: 0px 10px"
          v-hasPermi="[modulePermi + ':save']"
        >
          保存
        </el-button>
      </div>
      <el-form
        class="demo-form-inline"
        :model="form"
        ref="formMain"
        :rules="rules"
        label-width="125px"
        style="width: 100%"
      >
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="客户" prop="jzmName">
              <el-input
                :value="getDictLabel(form.jzmName, customerOptions)"
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="机型" prop="itmMstrJzdm">
              <HdSearchInput
                v-model="form.itmMstrJzdm"
                keyName="itmMstrJzdm"
                modulePath="rdmodule/researchData"
                @change="
                  (value) => {
                    handleChangeJzdm(value);
                  }
                "
                placeholder="请选择机种代码"
              ></HdSearchInput>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-tabs v-model="activeName">
        <el-tab-pane label="模具明细" name="first">
          <el-table
            :data="tableData"
            border
            style="width: 100%"
            :height="tableDataHeight"
            height="600px"
          >
            <el-table-column
              type="index"
              label="序号"
              width="50"
            ></el-table-column>
            <el-table-column
              v-for="(item, index) in options"
              :key="index"
              :width="item.width"
              :prop="item.prop"
              :label="item.label"
            ></el-table-column>
            <el-table-column label="验收结论" prop="acceptanceDesc">
              <template #default="scope">
                <el-input
                  v-model="scope.row.acceptanceDesc"
                  size="mini"
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column prop="receipt">
              <template #header>
                <span class="required">验收单</span>
              </template>
              <template #default="scope">
                <FileUpload
                  v-model="scope.row.receipt"
                  :limit="1"
                  :isShowTip="false"
                  :fileType="['png', 'jpg', 'jpeg', 'pdf']"
                ></FileUpload>
              </template>
            </el-table-column>
          </el-table>
        </el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>

<script>
//模具验收
import mixins from "@/mixins/common";
import RdmoduleService from "@/api/rdmodule/rdmodule";
export default {
  name: "MoldAcceptance",
  mixins: [mixins.customerOptions],
  data() {
    return {
      modulePermi: "rdmodule:MoldAcceptance",
      form: {
        jzmName: "",
        itmMstrJzdm: "",
      },
      activeName: "first",
      tableData: [],

      rules: {
        itmMstrJzdm: [{ required: true, message: "请选择机型" }],
      },
      tableDataHeight: "calc(100% - 60px)",
      options: [
        { prop: "mjmMjbh", label: "模具编号" },
        { prop: "itmCustwldm", label: "客户编码" },
        { prop: "bomWldm", label: "物料代码" },
        { prop: "itmPmgg", label: "产品名称" },
        { prop: "tonnage", label: "吨位" },
        { prop: "vacity", label: "穴数" },
      ],
    };
  },
  created() {
    this.$bus.$on("query-NewProductDiagram", (a) => {
      this.form.itmMstrJzdm = a;
      RdmoduleService.getInfo(a).then((res) => {
        if (res.code == 200) {
          this.form = res.data;
          this.$nextTick(() => {
            Object.assign(this.form, res.data);
          });
          this.tableData = res.data.moldAcceptanceList;
        }
      });
    });
  },
  beforeDestroy() {
    this.$bus.$off("query-NewProductDiagram");
  },
  methods: {
    handleSave(val) {
      if (val == 1) {
        this.form.researchStatus = 1;
      } else {
        this.form.researchStatus = 2;
      }
      //保存
      this.form.moldDetailList = this.tableData;
      this.form.researchPhase = "2";
      this.form.engineer = this.$store.state.user.nickName;
      this.$refs["formMain"].validate((valid) => {
        if (valid) {
          RdmoduleService.add(this.form).then((res) => {
            if (res.code == 200) {
              this.$message.success("保存成功");
            }
          });
        }
      });
    },
    handleChangeJzdm(val) {
      RdmoduleService.getInfo(val.itmMstrJzdm).then((res) => {
        if (res.code == 200) {
          this.form = res.data;
          this.$nextTick(() => {
            Object.assign(this.form, res.data);
          });
          this.tableData = res.data.moldAcceptanceList;
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped></style>
